/**
 * 
 */
package application;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import controller.ApplicationController;
import view.ApplicationView;
/**
 * @author Ken
 *
 */
public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Internet Download Manager");
		shell.setImage(new Image(display, "res/app_icon.png"));		
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		shell.setLayout(layout);
		Rectangle rect = Display.getDefault().getMonitors()[0].getBounds();
		
		int offsetX = 0, offsetY = 0, width = 800, height = 600;
		if (rect.width > width) {
			offsetX = (int)((rect.width - width) * 0.5f);
		}
		else width = rect.width;
		if (rect.height > height) {
			offsetY = (int)((rect.height - height) * 0.5f);
		}
		else height = rect.height;
		
		shell.setBounds(new Rectangle(offsetX, offsetY, width, height));
		ApplicationView view = new ApplicationView(shell, display);
		new ApplicationController(view);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
